var e, t, a = require("../../../@babel/runtime/helpers/interopRequireDefault"), n = a(require("../../../@babel/runtime/regenerator")), r = require("../../../@babel/runtime/helpers/toConsumableArray"), i = require("../../../@babel/runtime/helpers/asyncToGenerator"), s = a(require("../../../utils/api")), u = getApp();

Page({
    data: {
        headImg: "",
        id: "",
        pageNum: 1,
        pageSize: 8,
        list: [],
        list_len: 0,
        more: !0,
        finished: !1,
        typical: !1,
        input: "",
        toView: "",
        scrollTop: 0,
        rect: null,
        scroll_height: 0,
        dialogShow: !1,
        buttons: [ {
            text: "取消"
        }, {
            text: "确定"
        } ]
    },
    getList: function(e) {
        var t = this;
        return i(n.default.mark(function a() {
            var i, u, o;
            return n.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    return i = wx.getStorageSync("openid"), a.prev = 1, a.next = 4, s.default.questionDetail({
                        openid: i,
                        baseParentId: parseInt(e),
                        pageNum: t.data.pageNum,
                        pageSize: t.data.pageSize,
                        shared: !!t.data.typical
                    });

                  case 4:
                    u = a.sent, (o = t.data.list).unshift.apply(o, r(u.result.list)), t.setData({
                        id: e,
                        list: o,
                        list_len: u.result.list.length,
                        input: ""
                    }), u.result.list.length < t.data.pageSize && t.setData({
                        more: !1
                    }), a.next = 14;
                    break;

                  case 11:
                    a.prev = 11, a.t0 = a.catch(1), console.log(a.t0);

                  case 14:
                  case "end":
                    return a.stop();
                }
            }, a, null, [ [ 1, 11 ] ]);
        }))();
    },
    getLast: function(e) {
        var t = this;
        return i(n.default.mark(function a() {
            var r, i;
            return n.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    return r = wx.getStorageSync("openid"), a.prev = 1, a.next = 4, s.default.questionDetail({
                        openid: r,
                        baseParentId: parseInt(e),
                        pageNum: 1,
                        pageSize: t.data.pageSize,
                        shared: !!t.data.typical
                    });

                  case 4:
                    return i = a.sent, a.abrupt("return", i.result.list.pop());

                  case 8:
                    a.prev = 8, a.t0 = a.catch(1), console.log(a.t0);

                  case 11:
                  case "end":
                    return a.stop();
                }
            }, a, null, [ [ 1, 8 ] ]);
        }))();
    },
    onLoad: (t = i(n.default.mark(function e(t) {
        return n.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                return this.setData({
                    finished: "true" == t.finished,
                    typical: "true" == t.typical
                }), e.next = 3, this.getList(t.id);

              case 3:
                this.setData({
                    id: t.id,
                    headImg: u.globalData.userInfo.headImg,
                    toView: "item" + (this.data.list.length - 1),
                    anonymous: t.anonymous
                });

              case 4:
              case "end":
                return e.stop();
            }
        }, e, this);
    })), function(e) {
        return t.apply(this, arguments);
    }),
    onReady: (e = i(n.default.mark(function e() {
        var t = this;
        return n.default.wrap(function(e) {
            for (;;) switch (e.prev = e.next) {
              case 0:
                wx.createSelectorQuery().select("#scroll").boundingClientRect(function(e) {
                    t.setData({
                        scroll_height: e.height - 10
                    });
                }).exec();

              case 3:
              case "end":
                return e.stop();
            }
        }, e);
    })), function() {
        return e.apply(this, arguments);
    }),
    tapUpper: function() {
        var e = this;
        return i(n.default.mark(function t() {
            var a, r;
            return n.default.wrap(function(t) {
                for (;;) switch (t.prev = t.next) {
                  case 0:
                    if (e.data.more) {
                        t.next = 2;
                        break;
                    }
                    return t.abrupt("return");

                  case 2:
                    return e.setData({
                        pageNum: ++e.data.pageNum
                    }), a = wx.createSelectorQuery(), r = 0, a.select("#list_wrapper").boundingClientRect(function() {
                        var e = i(n.default.mark(function e(t) {
                            return n.default.wrap(function(e) {
                                for (;;) switch (e.prev = e.next) {
                                  case 0:
                                    r = t.height;

                                  case 1:
                                  case "end":
                                    return e.stop();
                                }
                            }, e);
                        }));
                        return function(t) {
                            return e.apply(this, arguments);
                        };
                    }()).exec(), a = null, t.next = 9, e.getList(e.data.id);

                  case 9:
                    wx.createSelectorQuery().select("#list_wrapper").boundingClientRect(function() {
                        var t = i(n.default.mark(function t(a) {
                            return n.default.wrap(function(t) {
                                for (;;) switch (t.prev = t.next) {
                                  case 0:
                                    e.setData({
                                        scrollTop: a.height - r - e.data.scroll_height
                                    });

                                  case 1:
                                  case "end":
                                    return t.stop();
                                }
                            }, t);
                        }));
                        return function(e) {
                            return t.apply(this, arguments);
                        };
                    }()).exec(), null;

                  case 12:
                  case "end":
                    return t.stop();
                }
            }, t);
        }))();
    },
    tapFinish: function() {
        this.setData({
            dialogShow: !0
        });
    },
    tapDialogButton: function(e) {
        var t = this;
        return i(n.default.mark(function a() {
            var r;
            return n.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    if (0 != e.detail.index) {
                        a.next = 3;
                        break;
                    }
                    return t.setData({
                        dialogShow: !1
                    }), a.abrupt("return");

                  case 3:
                    if (t.data.finished) {
                        a.next = 15;
                        break;
                    }
                    return r = wx.getStorageSync("openid"), a.prev = 5, a.next = 8, s.default.finishQuestion({
                        openid: r,
                        baseParentId: parseInt(t.data.id)
                    });

                  case 8:
                    a.sent, t.setData({
                        dialogShow: !1,
                        finished: !0
                    }), a.next = 15;
                    break;

                  case 12:
                    a.prev = 12, a.t0 = a.catch(5), console.log(a.t0);

                  case 15:
                  case "end":
                    return a.stop();
                }
            }, a, null, [ [ 5, 12 ] ]);
        }))();
    },
    inputConfirm: function(e) {
        var t = this;
        return i(n.default.mark(function a() {
            var r, i, u;
            return n.default.wrap(function(a) {
                for (;;) switch (a.prev = a.next) {
                  case 0:
                    return r = wx.getStorageSync("openid"), a.prev = 1, a.next = 4, s.default.newQuestion({
                        openid: r,
                        anonymous: t.data.anonymous,
                        content: e.detail.value,
                        baseParentId: parseInt(t.data.id)
                    });

                  case 4:
                    a.sent, a.next = 10;
                    break;

                  case 7:
                    a.prev = 7, a.t0 = a.catch(1), console.log(a.t0);

                  case 10:
                    return i = t.data.list, a.next = 13, t.getLast(t.data.id);

                  case 13:
                    u = a.sent, i.push(u), t.setData({
                        list: i
                    }), t.setData({
                        input: "",
                        toView: "item" + (t.data.list.length - 1)
                    });

                  case 17:
                  case "end":
                    return a.stop();
                }
            }, a, null, [ [ 1, 7 ] ]);
        }))();
    }
});